# -*- coding: utf-8 -*-
import os
# 下面四个个导包不能删，服务器运行时找不到
from offline.ItemCFRecommend import ItemCFRecommender
from offline.contentBasedRecommend import ContentBasedRecommender
from offline.staticRecommend import StatisticsRecommender
from offline.ALSRecommend import OfflineRecommender


def exec_all(script_directory):
    recommender_path = os.path.join(script_directory, 'offline')
    # 获取 recommender_path 目录下的所有文件
    script_files = [f for f in os.listdir(recommender_path) if f.endswith(".py")]

    for file in script_files:
        # 拼接文件的绝对路径
        file_path = os.path.join(recommender_path, file)
        print(f"正在执行 {file_path}")

        try:
            # 打开文件并执行
            exec(open(file_path).read())
            print(f"执行完毕 {file_path}")
        except Exception as e:
            print(f"执行出错 {file_path}: {e}")

    # for file in recommender_path:
    #     print(file)


if __name__ == "__main__":
    # 获取当前脚本所在目录的绝对路径
    script_directory = os.path.dirname(os.path.abspath(__file__))
    exec_all(script_directory)
